import rxAjax from '@/assets/ajax.js';

//表单权限配置 api接口
export const customFormApi = {};
customFormApi.baseUrl= '/api-form/form/core/formSolution';
customFormApi.getByAlias =function(alias,id,params,action) {
    let url= customFormApi.baseUrl + "/" + alias + '/getByAlias'  ;
    let args=[];
    if(id){
        args.push("pk=" + id);
    }
    if(action){
        args.push("action=" + action);
    }
    if(args.length>0){
        url+="?" + args.join("&");
    }
    return rxAjax.postJson(url,params);
}
customFormApi.validPreConditionByList=function(preCondConfig,rows){
    let url= '/api-form/form/core/formBoList/validPreByButton';
    rows=rows || [];
    return rxAjax.postJson(url,{config:preCondConfig,rows:rows}).then (res => {
        return res.data
    });
}
customFormApi.formSolutionRemoveById=function(params) {
    let url= '/api-form/form/core/formSolution/removeById';
    return rxAjax.postJson(url,params).then (res => {
        return res
    });
}
customFormApi.validPreByButton=function(preCondConfig,formJson){
    var url ='/api-form/form/core/formSolution/validPreByButton';
    return rxAjax.postJson(url,{config:preCondConfig,formJson:formJson});
}
/**
 * 保存表单数据。
 * {setting: {action: action, alias: self.formSolutionAlias}, data: data};
 * @param parameter
 * @returns {AxiosPromise|*}
 */
customFormApi.saveForm = function (parameter) {
    let url = '/api-form/form/core/formSolution/saveForm';
    return rxAjax.postJson(url, parameter);
}
/**
 * 获取满足条件的流程定义ID
 */
customFormApi.getFlowDefId=function(params){
    var url ="/api-form/form/core/formSolution/getFlowDefId";
    return rxAjax.postJson(url,params);
}
customFormApi.getProcessConfig = function(defId,defKey){

    let url = '/api-bpm/bpm/core/bpmInst/getProcessConfig?defId=' + defId;
    if(defKey){
        url ='/api-bpm/bpm/core/bpmInst/getProcessConfigByKey?defKey=' + defKey;
    }

    return rxAjax.get(url);
}
export default customFormApi